﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.AddBuffStack, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_AddBuffStack : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.AddBuffStack;
        public override string name => LevelEditorConst.AddBuffStack;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.AddBuffStack, "buff目标")]
        public int hostType;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.AddBuffStack, "LevelBuff表ID")]
        public int buffCid;
        [InspectorName("增加层数")] public int addStack;

        [Output("目标", false), VisibleIf(nameof(hostType), 4), Tooltip("仅参数1位4时有效")]
        public EditorLevelServiceTargetSetter tagOrMcid;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_AddBuffStack()
            {
                hostType = this.hostType,
                buffCid = this.buffCid,
                addStack = this.addStack
            };
            tagOrMcid = new EditorLevelServiceTargetSetter((x) => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_AddBuffStack rNode)
            {
                this.hostType = rNode.hostType;
                this.buffCid = rNode.buffCid;
                this.addStack = rNode.addStack;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_AddBuffStack rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}